
//% color="#ff9f06" iconWidth=50 iconHeight=40
namespace ina219_edu{
  

    //% block="power meter [OBJ] initialization until successful, I2C address [ADDR], calibration value [OFFSET]" blockType="command"
    //% OBJ.shadow="normal" OBJ.defl=ina1
    //% ADDR.shadow="dropdown"  ADDR.options="ADDR"
    //% OFFSET.shadow="number" OFFSET.defl=0
    export function ina219Init(parameter: any, block: any) {
        var obj=parameter.OBJ.code;
        var addr=parameter.ADDR.code;
        var offset=parameter.OFFSET.code;

        Generator.addImport('from dfrobot_ina219_education import INA219_EDUCATION');
        Generator.addCode(`${obj} = INA219_EDUCATION(i2c_addr=${addr})`);
        Generator.addCode(`${obj}.set_offset(${offset})`);
        Generator.addCode(`${obj}.begin()`);
    
    }

    //% block="power meter [OBJ] obtain no-load calibration value" blockType="command"
    //% OBJ.shadow="normal" OBJ.defl=ina1
    export function ina219ReadOffSet(parameter: any, block: any) {
        var obj=parameter.OBJ.code;
        Generator.addCode(`${obj}.print_offset()`);

        
    }


    //% block="power meter [OBJ] read load [VAL]" blockType="reporter"    
    //% OBJ.shadow="normal" OBJ.defl=ina1
    //% VAL.shadow="dropdown"  VAL.options="VAL"
    export function ina219Get(parameter: any, block: any) {
        var obj=parameter.OBJ.code;
        var val=parameter.VAL.code;
        Generator.addCode(`${obj}.${val}()`);
        
    }

    function replaceQuotationMarks(str:string){
            str=str.replace(/"/g, ""); //去除所有引号
            return str
    }


    
}
